package com.wxblockchain.prometheum.base;

import com.wxblockchain.core.base.BaseApplication;
import com.wxblockchain.prometheum.BuildConfig;

import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.dart.DartExecutor;

public class PrometheumApplication extends BaseApplication {
    @Override
    public void onCreate() {
        super.onCreate();

        flutterEngineInit();
    }

    @Override
    public boolean isDebug() {
        return BuildConfig.DEBUG;
    }

    // 引擎初始化
    private void flutterEngineInit() {
        engineInit(AppConfig.FlutterConfig.FLUTTER_ENGINE_MAIN_ID, AppConfig.FlutterConfig.FLUTTER_INIT_ROUTE_MAIN);
        engineInit(AppConfig.FlutterConfig.FLUTTER_ENGINE_POSITION_ID, AppConfig.FlutterConfig.FLUTTER_INIT_ROUTE_POSITION);
        engineInit(AppConfig.FlutterConfig.FLUTTER_ENGINE_ACCOUNT_ID, AppConfig.FlutterConfig.FLUTTER_INIT_ROUTE_ACCOUNT);
    }

    private void engineInit(String engineId, String initRoute) {
        FlutterEngine flutterEngine = new FlutterEngine(this);

        flutterEngine.getNavigationChannel().setInitialRoute(initRoute);

        flutterEngine.getDartExecutor().executeDartEntrypoint(
                DartExecutor.DartEntrypoint.createDefault()
        );

        FlutterEngineCache.getInstance().put(engineId, flutterEngine);
    }

}
